import pygame
from random import *

import main

#泡泡类
class paoPao():
    def __init__(self):
        #加载泡泡图片
        self.image = pygame.image.load("images/paopao.png").convert_alpha()
        #获取泡泡的矩形区域
        self.rect = self.image.get_rect()
        #上升速度
        self.speed = 8
        #上升过程左右摇晃的方向（1:左,2:右）
        self.direction = 1
        #初始位置
        self.rect.center = (randint(0,800) ,560)

    #泡泡上升
    def rise(self):
        if self.rect.bottom > 0:
            self.rect.bottom -= self.speed
            if self.direction == 1:
                self.rect.left -= 4
                self.direction = 2
            elif self.direction == 2:
                self.rect.left += 4
                self.direction = 1
        else:
            self.rect.center = (randint(0,800) ,560)

    #绘制泡泡
    def display_paopao(self):
        main.screen.blit(self.image,self.rect)
        
        
